/**
 * 
 */
package org.t2.backstage.module.rank;

import org.gaming.backstage.PageData;
import org.gaming.service.advice.ResponseResult;
import org.gaming.service.apidoc.annotation.ApiDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.t2.backstage.module.gameserver.model.GameServer;
import org.t2.backstage.module.gameserver.service.GameServerService;
import org.t2.backstage.util.T2HttpUtil;

import sh.t2.share.apiutil.GameApi;
import sh.t2.share.module.rank.RankApiProtocol.RankQueryRequest;
import sh.t2.share.module.rank.RankApiProtocol.RankQueryResponse;
import sh.t2.share.module.rank.RankWebData;

/**
 * 
 */
@Controller
public class RankController {

	@Autowired
	private GameServerService gameServerService;

	@ApiDocument("查询排行榜数据")
	@RequestMapping(value = "/rank/data.auth")
	@ResponseBody
	public PageData<RankWebData> info(RankQuery query) {
		if (query.getServerUid() <= 0) {
			return new PageData<>();
		}
		
		GameServer gameServer = gameServerService.getEntity(0, query.getServerUid());

		RankQueryRequest request = new RankQueryRequest();
		request.rankType = query.getRankType();
		request.playerId = query.getPlayerId();
		ResponseResult<RankQueryResponse> response = T2HttpUtil.jsonPost(gameServer, GameApi.rankInfo, request,
				RankQueryResponse.class);

		PageData<RankWebData> pageData = new PageData<>();
		pageData.setCount(response.getData().datas.size());
		pageData.setData(response.getData().datas);
		return pageData;
	}
}
